package com.taotao.portal.service.impl;

import com.taotao.pojo.User;
import com.taotao.portal.service.UserService;
import com.taotao.util.HttpClientUtil;
import com.taotao.util.TaotaoResult;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;


/**
 * describe:
 *
 * @author hong.zheng
 * @date 2018/09/25
 */
@Service
public class UserServiceImpl implements UserService{
    @Value("${SSO_BASE_URL}")
    private String SSO_BASE_URL;

    @Value("${GET_USER_BY_TOKEN_URL}")
    private String GET_USER_BY_TOKEN_URL;

    @Value("${SHOW_LOGIN}")
    private String SHOW_LOGIN;


    @Override
    public User getUserByToken(String token) {
        //根据token取用户信息
        String stringResult = HttpClientUtil.doGet(SSO_BASE_URL + GET_USER_BY_TOKEN_URL + token);
        //把返回结果转换成java对象
        TaotaoResult taotaoResult = TaotaoResult.formatToPojo(stringResult, User.class);
        //判断返回状态
        if (taotaoResult.getStatus() == 200) {
            //取User对象
            User user = (User) taotaoResult.getData();
            return user;
        }

        return null;
    }

    @Override
    public String getLoginUrl() {
        return SSO_BASE_URL+SHOW_LOGIN;
    }

}
